<template>
  <transition appear :duration="180" enter-active-class="ani-in" leave-active-class="ani-out">
    <div class="cover">
      <div class="bg"></div>

      <div class="panel">
        <!-- 关闭按钮 -->
        <span class="close iconfont icon-guanbi" @click="closeAction"></span>

        <!-- 头部 -->
        <slot name="header">
          <!-- 后备内容 -->
          <header class="header border-bottom">
            <h3 class="title">{{ title }}</h3>
          </header>
        </slot>

        <!-- 内容部分 -->
        <div class="content">
          <slot />
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "cover-view",
  props: {
    title: String,
  },
  methods: {
    // 关闭按钮的点击事件
    closeAction() {
      this.$emit("close");
    },
  },
};
</script>

<style scoped lang="scss">
.cover {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: transparent;
  .bg {
    width: 100%;
    height: 100%;
    background-color: rgba($color: #000000, $alpha: 0.5);
  }
  .panel {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    background: #fff;
    .close {
      position: absolute;
      top: 0;
      right: 0;
      width: 50px;
      height: 50px;
      z-index: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      color: #999;
    }
  }
  .header {
    height: 50px;
    .title {
      text-align: center;
      line-height: 50px;
      font-size: 16px;
      color: #333;
    }
  }
  .content {
    height: 45vh;
    overflow: auto;
  }
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
.ani-in .bg {
  animation: fadeIn 200ms;
}

@keyframes fadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
.ani-out .bg {
  animation: fadeOut 200ms;
}

@keyframes slideInBottom {
  0%{
    transform: translateY(100%);
  }
  100%{
    transform: translateY(0);
  }
}
.ani-in .panel {
  animation: slideInBottom 200ms;
}

@keyframes slideOutBottom {
  0%{
    transform: translateY(0);
  }
  100%{
    transform: translateY(100%);
  }
}
.ani-out .panel {
  animation: slideOutBottom 200ms;
}

</style>
